<template>
  <div id="echartsComp" :style="{ height: height, width: width }"></div>
</template>

<script>
import { getCurrentInstance } from "vue";
import resize from "./mixins/resize";

export default {
  name: "EchartsComp",
  mixins: [resize],
  props: {
    options: {
      type: Object,
      required: true,
    },
    width: {
      type: String,
      default: "200px",
    },
    height: {
      type: String,
      default: "200px",
    },
  },
  mounted() {
    // 渲染图表
    const { proxy } = getCurrentInstance();
    this.chart = proxy.$echarts.init(document.getElementById("echartsComp"));
    this.chart.setOption(this.options);

    // 事件
    this.chart.on("click", function (params) {
      console.log(params);
    });
    // 分辨率调整刷新图表
    window.onresize = () => {
      this.chart.resize();
    };
  },
  methods: {
    Refresh() {
      console.log(this.options);
      this.chart.setOption(this.options);
    },
  },
};
</script>
